Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lock mode to query builder #4316

Closed
wants to merge 12 commits into from
Closed

Conversation

carnage
Copy link

@carnage carnage commented Oct 1, 2020

This is a prototype of adding the ability to add locks when building a query using the query builder in a platform agnostic way. For the most part, this mimics the way that it is done in the ORM query builder.

Q A
Type feature
BC Break no
Fixed issues N/A

Summary

  • Adds get/set lock mode to query builder.
  • Query builder will append the correct lock SQL based on the current database platform.


$query .= ($this->sqlParts['from'] ? ' FROM ' . implode(', ', $this->getFromClauses()) : '')
$query .= $databasePlatform->appendLockHint($from, $this->lockMode)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An potential issue here is if:

  • Platform is MsSQL/SqlAnywhere
  • Lock mode is set
  • From clause is empty

An invalid query will be generated. Should this be considered user error (lock mode without a from is nonsensical) or should the code avoid adding the lock statement?

*/
public function setLockMode(int $lockMode)
{
$this->lockMode = $lockMode;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ORM query builder includes defensive coding around not allowing locks to be set outside of a transaction (they would be immediately released), should that be added here?

I lean towards no given the warning comments at the top of the class that it is the user's responsibility to use this class to generate valid queries.

@carnage carnage changed the title Prototype for adding lock mode to query builder Add lock mode to query builder Oct 3, 2020
@carnage
Copy link
Author

carnage commented Oct 3, 2020

This is ready for review/merge now

@morozov
Copy link
Member

morozov commented Oct 4, 2020

Since this functionality is highly dependent on the underlying platform, it will need cross-platform functional tests first of all. As far as I understand, it's challenging to test locking scenarios in a single-threaded environment, so it's enough to just execute the queries with all supported locking modes on all supported platforms and make sure that they are valid.

Additionally, please provide an automated test in a free form (see #4279 for example) that describes the intended behavior of the new API.

Also, note that since 2.11.0 has been released, 2.11.x only accept bug fixes. The correct branch for new features and improvements is 3.0.x.

@carnage
Copy link
Author

carnage commented Oct 8, 2020

Not quite sure what you mean by an automated test in a free form?

Do you just mean a script which connects to (eg MySQL) executes a query with a lock; sleeps for 10 secs then quits such that you could run two in parallel manually to show it works?

I take it that there are no plans for a 2.12.0 version then?

@morozov
Copy link
Member

morozov commented Oct 9, 2020

Do you just mean a script which connects to (eg MySQL) executes a query with a lock; sleeps for 10 secs then quits such that you could run two in parallel manually to show it works?

Yes, because you cannot run two parallel processes in a functional test. But the script should not only work with MySQL but with all supported platforms.

I take it that there are no plans for a 2.12.0 version then?

No. Please retarget to 3.0.x.

@carnage carnage changed the base branch from 2.11.x to 3.0.x October 10, 2020 11:40
@vaclavvanik
Copy link

This feature looks amazing. @carnage I am not sure, is the work done?

@morozov morozov closed this Apr 21, 2021
@morozov morozov deleted the branch doctrine:3.1.x April 21, 2021 16:26
@vaclavvanik
Copy link

@morozov should I ask why was this PR closed? This improvement is imo good.

@morozov
Copy link
Member

morozov commented Apr 23, 2021

@vaclavvanik the PR got closed because I removed the branch. I'll retarget it against 3.1.x. Sorry for the inconvenience.

@morozov morozov reopened this Apr 23, 2021
@morozov morozov changed the base branch from 3.0.x to 3.1.x April 23, 2021 16:10
@vaclavvanik
Copy link

@morozov ok, no problem :-)

@vaclavvanik
Copy link

@carnage do you want to finish this PR? If no I would like to continue.

@carnage
Copy link
Author

carnage commented Apr 26, 2021

Hi, Please feel free to bring it up to scratch to get it merged, just leave my original credit in :) the one thing missing was a "free form" test to demonstrate it working and any new work to resolve conflicts and get the build to pass. I was working on this as part of a client project which got terminated abruptly and I haven't had the time to come back to it.

@morozov
Copy link
Member

morozov commented Nov 6, 2021

Closing due to the lack of progress.

@morozov morozov closed this Nov 6, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants